package com.wjy.icu.controller;


import cn.hutool.core.util.HexUtil;
import com.wjy.icu.common.annotation.PassToken;
import com.wjy.icu.common.core.domain.R;
import com.wjy.icu.emqx.client.MqttPushClient;
import com.wjy.icu.emqx.utils.MqttUtils;
import com.wjy.icu.service.IMqttService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Description:
 * @author: wangjunyong
 * @date: 2021/9/24 9:27
 */
@RestController
@RequestMapping("mqttDemo")
public class MqttDemoController {
    @Autowired
    private MqttPushClient mqttPushClient;
    @Autowired
    private IMqttService mqttService;
    /**
     * @author liujianfu
     * @description    测试发布主题
     * @date 2021/8/16 15:04
     * @return RUtils
     */
    @PassToken
    @GetMapping(value = "/publishTopic")
    public R publishTopic(String topic,String aa) {
//        String s = HexUtil.decodeHexStr("68020202FA0016");
        byte[] bytes = HexUtil.decodeHex(aa);
        String s1 = MqttUtils.Bytes2HexString(bytes);
        System.out.println("message:"+s1 );
        mqttPushClient.publish(0,false,topic,bytes);
        System.out.println("message成功");
        return R.ok("OK");
    }
}
